<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="./jquery.js"></script>
        <script type="text/javascript">
            jQuery(document).ready(function(){
                jQuery("form[name=form1] input[name=txtPhotoName]").blur(function(){
                    jQuery.ajax({
                        type:"GET",
                        data:"key="+$("form[name=form1] input[name=txtPhotoName]").val(),
                        url:"check_exist.php?type=4",
                        success:function(result){
                            $("#spAvailability").html(result);
                        }
                    });
                });
            });
        </script>
    </head>
    <body>
        <?php
        require 'connect.inc';
        require 'session.inc';
        $res = "";
        $result = "";
        $iduser = $_SESSION['iduser'];
        $idAlbum = $_REQUEST['album_id'];
        $idUser = $_SESSION["iduser"];
        $res .="<table width='100%' border='1' cellspacing='0'>
                    <tbody>
                        <tr></tr>
                        <tr>
                            <td>
                                <img src='logo.jpg'>
                            </td>
                            <td>
                                <h1>Photo Album Website</h1>
                            </td>
                        </tr>
                        <tr>
                            <td width='20%' valign='top'>
                                <a href='index.php'>Home</a>
                                <br>
                                <a href='my_albums.php'>My Albums</a>
                                <br>
                                <a href='users.php'>Other persons</a>
                            </td><td>
                            <table>
                                <tbody>
                                    <tr>
                                        <td rowspan='5'>";

        $strSQL = "SELECT * FROM `album` a
                        WHERE album_id = $idAlbum and public = 1";
        $result = mysql_query($strSQL);
        if ($result)
            while ($row = mysql_fetch_array($result)) {
                $owner = $row['owner'];

                $avatar = $row['avatar'];
                $path = "./upload/$owner/$idAlbum/avatar/$avatar";
                $res .= "<img src='$path' hieght ='200'>";
                $fullname = "";
                $r = mysql_query("SELECT * FROM Users where user_id = $idUser");
                while ($ro = mysql_fetch_array($r)) {
                    $fullname .= $ro['full_name'];
                }
                $name = $row['album_name'];
                $dc = $row['date_created'];
                $dm = $row['date_modified'];
                $pl = $row['public'];
                $res .= "</td>
                            <td>$name</td>
                        </tr>
                        <tr>
                            <td>$fullname</td>
                        </tr>
                        <tr>
                            <td>$dc</td>
                        </tr>
                        <tr>
                            <td>$dm</td>
                        </tr>
                        <tr>
                            <td>Public: $pl</td>
                        </tr>
                    </tbody>
                </table>";
                break;
            }

        $res .= " <br/><hr>
                        <center>
                        
                    </center>
                   <form enctype='multipart/form-data' method='post' action='view_album.php?album_id=$idAlbum' name='form1'>
                    <table>
                        <tbody>
                            <tr>
                                <td>

                                </td>
                            </tr>
                            <tr>
                                <td>Search in photo: </td>
                                <td>
                                    <input type='text' value='' name='txtPhotoName'>
                                    <input type='submit' value='Search' name='btnSearch'>
                                </td>
                            </tr>
                            <tr>
                                <td>Foresee: </td>
                                <td>
                                    <span id='spAvailability' style='color: red'>
                                        <font style='color:red'></font>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                            <td></td>
                                <td>
                                    
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>";

        if (isset($_POST["btnSearch"])) {
            $name = $_REQUEST["txtPhotoName"];

            $strSQL = "SELECT * FROM photo WHERE photo_name like '%$name%'";
            $res .="<br/><hr>
                        Result: <a href='view_album.php?album_id=$idAlbum'>Reset</a><br/>
                     <br>";
        } else {
            $strSQL = "SELECT * FROM `photo`
                    WHERE album_id = $idAlbum";
            $res .="<br/><hr>
                        Photo in album:
                     <br>";
        }

        //echo $strSQL;
        $result = mysql_query($strSQL);
        if ($result) {
            if (mysql_num_rows($result) < 1)
                $res .= "No photo!";
            else
                while ($row = mysql_fetch_array($result)) {
                    $idPhoto = $row["album_id"];
                    $image = $row["image"];
                    $name = $row["photo_name"];
                    $res .= "<table style='float:left;'>
                        <tbody>
                            <tr>
                                <td>
                                    <img height='100' src='./upload/$iduser/$idAlbum/$image'>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <a href='# '>$name</a>
                                </td>
                            </tr>
                        </tbody>
                    </table>";
                }
        }
        // User logged in

        $res .= " <td width='20%' valign='top'>
                Wellcom <a href='#'>" . $_SESSION["username"] . "</a>!
                |
                <a href='logout.php'>Logout</a></td>
            </tr>
        </tbody>
        </table>";

        echo $res;
        ?>
    </body>

</html>
